import { ShopRole } from './shop-role.entity'
import { Account } from '../account'

import { ShopGood } from './shop-good.entity'
import { Company } from '../company/company.entity'
import { ShopEmployee } from './shop-employee.entity'
import { ShopOrder } from './shop-order.entity'
import { JoinTable, OneToMany, Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
import { ManyToOne } from 'typeorm'
import { Member } from '../member'
import { ShopWork } from './shop-work.entity'
import { ShopTask } from './shop-task.entity'

// 店铺

@Entity()
export class Shop {
  @PrimaryGeneratedColumn()
  id: number

  @Column({
    comment: '名称'
  })
  business_name: string

  @Column({
    comment: '分店名称'
  })
  branch_name: string

  @Column({
    comment: '电话'
  })
  telephone: string

  @Column({
    comment: '图片'
  })
  photo_list: string

  @Column()
  recommend: string

  @Column()
  special: string

  @Column()
  introduction: string

  @Column()
  open_time: string

  @Column()
  avg_price: string

  @Column()
  shop_logo: string

  @Column()
  offset_type: string
  @Column()
  province: string
  @Column()
  city: string
  @Column()
  district: string
  @Column()
  address: string
  @Column()
  longitude: string
  @Column()
  latitude: string

  /**
   * 店主
   * 一个店铺只能属于一个人，一个人可以有多个店铺
   */
  @ManyToOne(type => Member, member => member.shops, { cascade: true })
  @JoinTable()
  member: Member

  @ManyToOne(type => Company, company => company.shops, { cascade: true })
  @JoinTable()
  company: Company

  @OneToMany(type => ShopEmployee, employee => employee.shop)
  employees: ShopEmployee[]

  /**
   * 店铺订单
   * 一个店铺可以有多个订单，一个订单只能属于一个店铺
   */
  @OneToMany(type => ShopOrder, order => order.shop)
  orders: ShopOrder[]

  /**
   * 店铺工单
   * 一个店铺可以有多个工单，一个工单只能属于一个店铺
   */
  @OneToMany(type => ShopWork, work => work.shop)
  works: ShopWork[]

  /**
   * 店铺任务
   * 一个店铺可以有多个任务，一个工单只能属于一个任务
   */
  @OneToMany(type => ShopTask, task => task.shop)
  tasks: ShopTask[]

  @OneToMany(type => ShopGood, good => good.shop)
  goods: ShopGood[]
  // 店铺角色
  @OneToMany(type => ShopRole, role => role.shop)
  roles: ShopRole[]
  // 店铺所属公众号
  @ManyToOne(type => Account, account => account.shops)
  account: Account
}
